import VueRouter from "vue-router";
// import Home from '@/views/Home.vue'
import Vue from "vue";
import store from "@/store/store";
const Home = () => import('@/views/Home.vue')
const Plate = () => import("@/views/Plate.vue")
const index = () => import("@/views/Index.vue")
const InfoCenter = () => import("@/views/InfoCenter.vue")
const MessageCenter = () => import("@/views/MessageCenter.vue")
const ReplyItemList = () => import("@/components/MessageCenter/ReplyItemList.vue")
const AtItemList = () => import("@/components/MessageCenter/AtItemList.vue")
const LikeReplyItemList = () => import("@/components/MessageCenter/LikeReplyItemList.vue")
const Editor = () => import("@/views/Editor.vue")
const Forum = () => import("@/views/Forum.vue")
const Post = () => import("@/views/Post.vue")
const routes = [
    {
        path: '/',
        component: Home,
        children: [
            {
                name: 'index',
                path: '',
                component: index,
                meta:{
                    title:"首页"
                }
            },
            {
                name: 'forums',
                path: 'forums',
                component: Plate,
                meta:{
                    title:"板块"
                }
            },
            {
                name: 'createForum',
                path: 'forums/create',
                component: () => import("@/views/ForumCreate.vue"),
                meta:{
                    title:"板块-创建",
                    requireLogin: true
                }
            },
            {
                name: 'info-center',
                path: 'info-center/:userId',
                component: InfoCenter,
                redirect: to => {
                    // 方法接收 目标路由 作为参数
                    // return 重定向的 字符串路径/路径对象
                    if (store.state.user.info.userId == to.params.userId) {
                        return { name: "self-info"}
                    }
                    return { name: "postList"}
                },
                props: true,
                children: [
                    
                    {
                        path: 'self',
                        name: 'self-info',
                        components: {
                            "self-info": () => import("@/components/InfoCenterItems/SelfInfo.vue")
                        },
                        meta:{
                            title:"个人信息",
                            requireLogin: true
                        }
                    },
                    {
                        path: 'postList',
                        name: 'postList',
                        components: {
                            "postList": () => import("@/components/InfoCenterItems/PostList.vue")
                        },
                        meta:{
                            title:"文章"
                        }
                    },
                    {
                        path: 'collection',
                        name: 'collection',
                        components: {
                            "collection": () => import("@/components/InfoCenterItems/CollectionList.vue")
                        },
                        meta:{
                            title:"收藏",
                            requireLogin: true
                        }
                    },
                    {
                        path: 'followings',
                        name: 'followings',
                        components: {
                            "followings": () => import("@/components/InfoCenterItems/FollowsList.vue")
                        },
                        meta:{
                            title:"关注"
                        }
                    },
                    {
                        path: 'fans',
                        name: 'fans',
                        components: {
                            "fans": () => import("@/components/InfoCenterItems/FollowsList.vue")
                        },
                        meta:{
                            title:"粉丝"
                        }
                    },
                    {
                        path: 'history',
                        name: 'history',
                        components: {
                            "history": () => import("@/components/InfoCenterItems/HistoryList.vue")
                        },
                        meta:{
                            title:"浏览历史",
                            requireLogin: true
                        }
                    },
                    {
                        path:'ForumsFollowed',
                        name:'ForumsFollowed',
                        components:{
                            "ForumsFollowed":()=>import("@/components/InfoCenterItems/FollowingForums.vue")
                        },
                        meta:{
                            title:"关注板块",
                            requireLogin: true
                        }
                    }
                ]
            }
            ,
            {
                name: 'message-center',
                path: 'message-center',
                redirect:{name:'reply'},
                component: MessageCenter,
                meta:{
                    requireLogin:true
                },
                children: [
                    {
                        name: 'reply',
                        path: 'reply',
                        components: { reply: ReplyItemList },
                        meta:{
                            title:"回复我的",
                             requireLogin: true
                        }
                    },
                    {
                        name: 'like',
                        path: 'like',
                        components: { like: LikeReplyItemList },
                        meta:{
                            title:"收到的点赞",
                             requireLogin: true
                        }
                    },
                    {
                        name: 'at',
                        path: 'at',
                        components: { at: AtItemList }
                    },
                ]
            },
            {
                name: 'forum',
                path: 'forum/:id',
                component: Forum,
                props: true,
            },
            {
                name: 'edit',
                path: 'forum/:forumId/edit',
                component: Editor ,
                props: true,
                meta: {
                    requireLogin: true,
                    title:"编辑"
                }
            },
            {
                name: 'admin',
                path: 'forum/:forumId/admin',
                component: () => import("@/views/ForumAdmin.vue"),
                redirect:{name:'forumStatistics'},
                props: true,
                meta: {
                    requireLogin: true,
                    requireType:'admin',
                    title:'管理'
                },
                 
                children:[{
                    name:'forumStatistics',
                    path:'statistics',
                    component:()=>import("@/components/ForumAdmin/ForumStatistics.vue"),
                    meta: {
                        requireLogin: true,
                        requireType:'admin',
                        title:'管理-统计'
                    },
                    props:true
                },
                {
                    name:'forumAdministrators',
                    path:'administrators',
                    component:()=>import("@/components/ForumAdmin/AdminPersons.vue"),
                    meta: {
                        requireLogin: true,
                        requireType:'owner',
                        title:'管理-分配'
                    },
                    props:true
                },
                {
                    name:'forumBanAbout',
                    path:'ban-about',
                    component:()=>import("@/components/ForumAdmin/AdminPane.vue"),
                    meta: {
                        requireLogin: true,
                        requireType:'admin',
                        title:'管理-封禁'
                    },
                    props:true
                },
                {
                    name:'forumConfig',
                    path:'config',
                    component: () => import("@/views/ForumCreate.vue"),
                    meta: {
                        requireLogin: true,
                        requireType:'owner',
                        title:'管理-配置'
                    },
                    props:true
                }
            ]
            },
            {
                name: 'post',
                path: 'post/:postId',
                props: true,
                component: Post
            },
            {
                name:'search',
                path:'search',
                component: () => import("@/views/SearchResult.vue"),
            }
        ],
        
    },
    {
        path:'*',
        name:'404',
        component:() => import('@/views/404.vue')
    }
]
const router = new VueRouter(
    {
        routes
    }
)

Vue.use(VueRouter)
export default router